package thinking.a17.b2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author yuan
 */
class StringAddress {
    private String s;

    StringAddress(String s) {
        this.s = s;
    }

    @Override
    public String toString() {
        return hashCode() + " " + s;
    }
}
public class FillingLists {
    public static void main(String[] args) {
        List<StringAddress> list = new ArrayList<>(Collections.nCopies(4, new StringAddress("Hello")));
        System.out.println(list);
        Collections.fill(list, new StringAddress("World!"));
        System.out.println(list);
    }
}
/* Output:
[1163157884 Hello, 1163157884 Hello, 1163157884 Hello, 1163157884 Hello]
[1956725890 World!, 1956725890 World!, 1956725890 World!, 1956725890 World!]
学会了两个函数 Collections.nCopies(n, T) Collections.fill
值得注意的是nCopies出来的是相同的对象,hash Code相同
 */
